package org.bookie.facebook.components;

import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.IPageLoader;
import org.apache.tapestry.link.ILinkRenderer;
import org.apache.tapestry.link.PageLink;
import org.apache.tapestry.spec.IComponentSpecification;

/**
 * Extension over the {@link PageLink} component that will render fb:tab-item tag
 * with page links on it
 * 
 * @see http://wiki.developers.facebook.com/index.php/Fb:tabs
 * 
 * @author zubairov
 */
public abstract class TabItem extends PageLink {

	private static final ILinkRenderer renderer = new TabItemRenderer();
	
	@Override
	public void finishLoad(IRequestCycle cycle, IPageLoader loader,
			IComponentSpecification specification) {
		super.finishLoad(cycle, loader, specification);
		setRenderer(renderer);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void renderAdditionalAttributes(IMarkupWriter writer,
			IRequestCycle cycle) {
		writer.appendAttribute("title", getTitle());
		if (isSelected()) {
			writer.appendAttribute("selected", isSelected());
		}
		// Do not call super method hence
		// Do not render any other additional attributes
	}
	
	/**
	 * Getter for the parameter selected
	 * @return
	 */
    public abstract boolean isSelected();

	/**
	 * Getter for the parameter title
	 * @return
	 */
    public abstract String getTitle();
    
}
